{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Episode 3: Training the NLU model: pre-configured pipelines\n",
    "\n",
    "In this episode we talk about the pre-configured Rasa NLU training pipelines. \n",
    "\n",
    "### Updating the NLU configuration pipeline\n",
    "\n",
    "An NLU training pipeline can be specified by editing a file called config.yml in your project directory. By editing the cell below you can change the pre-configured pipelines from *supervised_embeddings* to *pretrained_embeddings_spacy* and test the performance.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "config_yml = \"\"\"\n",
    "\n",
    "language: en\n",
    "pipeline: supervised_embeddings\n",
    "\n",
    "\n",
    "policies:\n",
    "  - name: MemoizationPolicy\n",
    "  - name: KerasPolicy\n",
    "  - name: MappingPolicy\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "%store config_yml > config.yml"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Train and test the NLU model\n",
    "\n",
    "First, make sure to start the event loop for jupyter notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import nest_asyncio\n",
    "\n",
    "nest_asyncio.apply()\n",
    "print(\"Event loop ready.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Specify the model configuration, data files as well as the directory to store the trained model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import rasa\n",
    "from rasa.train import train_nlu\n",
    "\n",
    "config = \"config.yml\"\n",
    "training_files = \"data/\"\n",
    "domain = \"domain.yml\"\n",
    "output = \"models/\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Train the model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mod = train_nlu(config, training_files, output)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
